﻿using System;
using System.Collections.Generic;
using System.Text;
using EsenthelNet;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace EsenthelNetTest
{
    public class MyGame : Game
    {
        Astro astro;
        Image img;
        List<Chr> chrs;

        public override void InitPre()
        {
            App.Name = "World";
            App.Flag = AppFlags.Resizable;

            Paks.Add("C:/Users/Kevin/Desktop/Libs/EsenthelEngineSDK/Data/engine.pak");
            IOPath = "C:/Users/Kevin/Desktop/Libs/EsenthelEngineSDK/Data";
            D.Mode(800, 600);

            Cam.Dist = 10;
            Cam.Yaw = -MathHelper.Pi_4;
            Cam.Pitch = -0.5f;
            Cam.At.Set(16, 0, 16);
            
        }

        public override bool Init()
        {
            Physics.Create();
            Sky.Atmospheric();

            img = Image.Cache("gfx/sky/moon.gfx");

            Sun.Image = Image.Cache("gfx/sky/sun.gfx");
            Sun.Pos = !new Vec(1, 1, 1);
            
            astro = new Astro();
            astro.Image = img;
            astro.Pos = !new Vec(-1, 1, 1);
            astro.Size *= 0.6f;
            astro.Blend = false;
            astro.ImageColor = new Color(64, 64, 64, 0);
            astro.LightColor.Zero();

            World.Init();
            //World.SetObjType(out chrs, 4);

            World.New("world/sample.world");
            World.Update(Cam.At);
            
            return true;
        }

        public override void Shut()
        {
            
        }

        public override bool Update()
        {
            if (Kb.IsPushed(KeyboardButtons.Escape))
                return false;

            Cam.Handle(0.1f, 100.0f, CameraHandleFlags.Rotate | CameraHandleFlags.Zoom);
            World.Update(Cam.At);
            
            return true;
        }

        public void Render() {
            World.Draw();
            //switch (Renderer.Get())
            //{
            //    case RenderMode.RM_PREPARE:
            //        LightDir light = new LightDir(!new Vec(1, -1, 1), new Vec(1.0f));
            //        light.Add();

            //        break;
            //}
        }

        public override void Draw()
        {
            Renderer.Set(Render);

            D.Text(0.0f, 0.9f, "FPS: " + Timer.FPS.ToString());
        }

    }
}